package Week5.J0514;

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class 不相邻取数 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        long[] dp = new long[n + 1];

        for (int i = 1; i <= n; i++) {
            dp[i] = scanner.nextLong();
        }

        if (dp.length == 2) {
            System.out.println(dp[1]);
            return;
        } else if (dp.length == 3) {
            System.out.println(Math.max(dp[1], dp[2]));
            return;
        }

        dp[3] = Math.max(dp[2], dp[1] + dp[3]);


        for (int i = 4; i <= n; i++) {
            dp[i] += Math.max(dp[i - 2],
                    dp[i - 3]); // 因为是隔一个选, 所以可以有两种情况
        }

        System.out.println(Math.max(dp[dp.length - 1], dp[dp.length - 2]));
    }
}